package com.cdut.logistics.action.datacentre;

import java.util.ArrayList;
import java.util.List;

import com.cdut.logistics.intercepter.system.AuthorityIntercepter;
import com.cdut.logistics.model.dao.datacentre.Area;
import com.cdut.logistics.model.dao.datacentre.Dorm;
import com.cdut.logistics.service.impl.datacentre.AreaImpl;
import com.cdut.logistics.service.impl.datacentre.DormImpl;
import com.cdut.logistics.service.interf.datacentre.AreaService;
import com.cdut.logistics.service.interf.datacentre.DormService;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;

/**  
 * @ClassName: DeptController  
 * @Description: 宿舍管理控制类
 * @author wxt.xia
 * @date 2018年1月26日 下午3:28:25    
 */
//@Before(AuthorityIntercepter.class)
public class DormController extends Controller {
	
	private DormService dormService = new DormImpl();
	/**
	 * 
	 * @Title: query  
	 * @Description: 根据区域id查询宿舍
	 * @author wxt.xia
	 * @param json
	 * @throws
	 */
	public void query(){
		/*
		 * 解析json
		 */
		int area_id = Integer.valueOf((String) getPara("area_id"));
		List<Record> dormList = new ArrayList<Record>();
		try {
			 dormList = dormService.query(area_id);
			//System.out.println(deptList.get(0).getName());
		} catch (Exception e) {
			// TODO: handle exception
		}
		renderJson(dormList);
	}	
	
	/**
	 * 
	 * @Title: add  
	 * @Description: 新增宿舍
	 * @author wxt.xia
	 * @throws
	 */
	public void add(){
		/*
		 * 解析json
		 */
		
		//下面是测试数据，id需设置为自增长
		Dorm dorm = new Dorm();
		dorm.set("school_id", 1);
		dorm.set("name", "珙桐");
		dorm.set("school_id", 1);
		dorm.set("area_id", 1);
		
		try {
			dormService.add(dorm);
		} catch (Exception e) {
			
		}
	}
	
	/**
	 * 
	 * @Title: form  
	 * @Description: 修改信息
	 * @author wxt.xia
	 * @throws
	 */
	public void modify(){
		/*
		 * 解析json
		 */
		Dorm dorm = new Dorm();
		dorm.set("name", "123");
		dorm.set("id", 1);
		try {
			Dorm dormData = dorm.findById(dorm.get("id"));
			dormData.set("name","123");
			dormData.update();
		} catch (Exception e) {
			
		}
	}
	
	/**
	 * 
	 * @Title: remove  
	 * @Description: 删除宿舍
	 * @author wxt.xia
	 * @throws
	 */
	public void remove(){
		int id = 1;
		try {
			dormService.remove(id);
		} catch (Exception e) {
			
		}
	}
}
